package TestDemo;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-03-22
 * Time: 9:22
 */
public class TestDemo1 {

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            String[] arr = str.split(" ");
            for (int i = arr.length-1; i >= 0; i--) {
                System.out.print(arr[i]+' ');
            }
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();//数组个数
            int[] arr = new int[n];
            for(int i = 0;i < n;i++) {
                arr[i] = in.nextInt();
            }
            System.out.println(Sort(n,arr));
        }
    }
    public static int Sort(int n,int[] arr) {
        if(n <= 0) {
            return -1;
        }
        //需要建立一个标记位,用来记录之前两数比较的结果
        //flag=-1表示小于,0表示等于,1表示大于
        int flag = 0;
        int count = 1;
        for (int i = 1; i < n; i++) {
            if(arr[i] > arr[i-1]) {
                if(flag == 0) {
                    flag = 1;
                }
                if(flag == -1) {
                    flag = 0;
                    count++;
                }
            }else if(arr[i] < arr[i-1]) {
                if(flag == 0) {
                    flag = -1;
                }
                if(flag == 1) {
                    flag = 0;
                    count++;
                }
            }
        }
        return count;
    }
}
